﻿using System;
using System.Collections.Generic;
using System.Text;
using LinQProject;


namespace Infrastructure.Coding
{
    public class HtmlRender
    {
        public string GetTextForInvoice(Order newOrder, Invoice newInvoice, Provider myComp, IList<OrderDetail> listaOrderDetail, string percentInvoice)
        {
            //<img src='" + ImageManagement.GetImage("sigla_star_fog.JPG") + @"' alt='Stea_Scaune_Ieftine' /><br/><br/>
            string clientRJ = newOrder.Client.IsJuridical ? newOrder.Client.ClientReg : string.Empty;
            string clientCUI = newOrder.Client.IsJuridical ? newOrder.Client.ClientCUI : string.Empty;
            int intPercentInvoice = Convert.ToInt32(percentInvoice);
            decimal totalInvoice = newOrder.TotalCost * intPercentInvoice / 100;

            StringBuilder contents = new StringBuilder();
            contents.Append(@"<html>
                            <head>
								<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
									<style type='text/css'>
										.style1 
                                        {
											font-family: Arial, Helvetica, sans-serif;
											font-weight: bold;
										}
										.style5 
                                        {
											font-size: 12px;
											font-family: Arial, Helvetica, sans-serif;
										}
										.style16 {font-family: Arial, Helvetica, sans-serif}
										.style19 {font-size: 12px}
										.style20 
                                        {
											font-family: Tahoma;
											font-size: 10px;
										}
										.style22 {font-family: Arial, Helvetica, sans-serif; font-size: 9px; }
										.style24 {font-size: 20px}
										.style25 
                                        {
											font-size: 18px;
											font-weight: bold;
										}
										.style27 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; }
										.style28 {font-size: 10px}
										.style29 {
															font-size: 14px; 
															font-family: Arial, Helvetica, sans-serif;
														 }
										.style34 {
															font-family: Arial, Helvetica, sans-serif;
															font-size: 70px;
															font-weight: bold;
															color: __TodyBigColor__;
														 }
										.tableRejected {
											border-style:outset;
											border-width:5mm;
											border-color:#B2B2B2;
										}
										.tableNormal {
											border-width:1mm;
											border-color:#B2B2B2;
										}
										/*table.tableNormal td {
										border-width: 2px;
										border-style: solid;
										border-color: gray;
										}
										table.tableRejected td {
										border-width: 2px;
										border-style: solid;
										border-color: gray;
										}
										table.tableNormal th {
										border-width: 2px;
										border-style: solid;
										border-color: gray;
										}
										table.tableRejected th {
										border-width: 2px;
										border-style: solid;
										border-color: gray;
										}*/
									</style>
                            </head>
                            <body marginwidth='0' marginheight='0' leftmargin='0' topmargin='0'>
                              <center>");
            contents.Append(@"      <table style='top:0px' border='1' width='850px'>
                                    <tbody>
                                        <tr>
                                            <td align='center' style='font-family:Verdana; font-size:xx-small;'>
                                                <b>" + myComp.ProviderName + @"</b> " + myComp.ProviderAddress + @" " + myComp.City + @" " + myComp.Region.RegionName + @"<br/><br/> 
                                                <span style='font-family: Broadway;font-size:large;'>
                                                    <b>FACTURA PROFORMA NR.&nbsp;" + newInvoice.InvoiceId + @"</b>
                                                 </span>
                                            </td>
                                        </tr>
                                        <tr>
							                <td>
                                                <table border='0' cellpadding='5' cellspacing='5' height='0%' width='100%' style='font-family:Verdana; font-size:x-small;'>");
            contents.Append(@"                      <tbody>
                                                        <tr>
                                                             <td colspan='2' align='center'> 
                                                                <b>Data:</b><b>" + DateTime.Now.ToString("dd/MM/yyyy") + @"</b>&nbsp;&nbsp;&nbsp<b>Valabil pana la:</b><b>" + DateTime.Now.AddDays(7).ToString("dd/MM/yyyy") + @"</b>
                                                             </td>
                                                        </tr>
                                                        <tr>
                                                            <td valign='top' align='center'>
                                                                <table style='border-width: 2px; border-style: solid; border-color: gray; font-family:Verdana; font-size:x-small;background-color: #F5F5F5;'>
                                                                    <tr><td>Furnizor:</td><td align='left'><b>" + myComp.ProviderName + @"</b></td></tr>
                                                                    <tr><td>RJ:</td><td>" + myComp.ProviderRegCom + @"</td></tr>
                                                                    <tr><td>Cod Fiscal:</td><td>" + myComp.ProviderCUI + @"</td></tr>
                                                                    <tr><td>Sediul:</td><td>" + myComp.ProviderAddress + " " + myComp.City + " " + myComp.Region.RegionName + @"</td></tr>
                                                                    <tr><td>Telefon:</td><td>" + myComp.ProviderPhone + @"</td></tr>
                                                                    <tr><td>Mobil:</td><td>" + myComp.ProviderMobil + @"</td></tr>
                                                                    <tr><td>Fax:</td><td>" + myComp.ProviderPhone + @"</td></tr>
                                                                    <tr><td>Cont:</td><td>" + myComp.ProviderCont + @"</td></tr>
                                                                    <tr><td>Banca:</td><td>" + myComp.ProviderBank + @"</td></tr>        
                                                                </table>        
                                                            </td>");
            contents.Append(@"                              <td valign='top' align='center'>
                                                                <table style='border-width: 2px; border-style: solid; border-color: gray; font-family:Verdana; font-size:x-small;background-color: #F5F5F5;'>
                                                                    <tr><td>Cumparator:</td><td><b>" + newOrder.Client.ClientName + @"</b></td></tr>
                                                                    <tr><td>RJ:</td><td>" + clientRJ + @"</td></tr>
                                                                    <tr><td>CUI:</td><td>" + clientCUI + @"</td></tr>
                                                                    <tr><td>Sediul:</td><td>" + newOrder.Client.ClientAddress + @"</td></tr>
                                                                    <tr><td>Telefon:</td><td>" + newOrder.Client.ClientPhone + @"</td></tr>
                                                                    <tr><td>Mobil:</td><td>" + newOrder.Client.ClientMobil + @"</td></tr>
                                                                    <tr><td>Fax:</td><td>" + newOrder.Client.ClientPhone + @"</td></tr>
                                                                    <tr><td>Cont:</td><td>" + newOrder.Client.ClientCont + @"</td></tr>
                                                                    <tr><td>Banca:</td><td>" + newOrder.Client.ClientBank + @"</td></tr>            
                                                                </table>
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </td>
                                        </tr>");
            contents.Append(@"          <tr>
                                            <td align='center' valign='center'>
                                                <span style='font-family: Verdana ;font-size:14px;font-weight: bold; '>
                                                    <b> DETALII CORESPUNZATOARE COMENZII EFECTUATE </b>
                                                </span>
                                               <br/><br/>");
            contents.Append(@"                  <table width='100%' border='2' style='font-family:Verdana; font-size:x-small;'>
                                                    <thead style='border-width:medium;'>
                                                        <tr>
                                                            <th align='center'>Produs</th>
                                                            <th align='center'>Material</th>
                                                            <th align='center'>Cantitate</th>
                                                            <th align='center'>Pret unitar fara Tva</th>
                                                            <th align='center'>Valoare fara TVA</th>
                                                            <th align='center'>Valoare TVA</th>
                                                        </tr>
                                                    </thead>
                                                    <tbody>");
            foreach (OrderDetail orderDetail in listaOrderDetail)
            {
                contents.Append(@"<tr>
                                                          
                                                            <td align='right'>" + String.Format("{0:#.#,00}", orderDetail.ProductUnitPrice / (decimal)1.19) + @"</td>
                                                            <td align='right'>" + String.Format("{0:#.#,00}", orderDetail.ProductTotalPrice / (decimal)1.19) + @"</td>
                                                            <td align='right'>" + String.Format("{0:#.#,00}", (orderDetail.ProductTotalPrice / (decimal)1.19) * (decimal)0.19) + @"</td>
                                                        </tr>");
            }
            contents.Append(@"<tr>
                                                            <td align='left' colspan='4'>Total</td>
                                                            <td align='right'>" + String.Format("{0:#.#,00}", newOrder.TotalCost / (decimal)1.19) + @"</td>        
                                                            <td align='right'>" + String.Format("{0:#.#,00}", newOrder.TotalCost * (decimal)0.19 / (decimal)1.19) + @"</td>      
                                                       </tr>");
            contents.Append(@"<tr>
                                                            <td align='left' colspan='4'>Total comanda</td>
                                                            <td colspan='2' align='right'>" + String.Format("{0:#.#,00}", newOrder.TotalCost) + @"</td>        
                                                       </tr>");
            contents.Append(@"                      </tbody>
                                                </table>");
            contents.Append(@"              </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <table width='100%' border='2' style='font-family:Verdana; font-size:x-small;' >
                                                    <tr>
                                                        <td> <b>TOTAL DE PLATA CU TVA (" + percentInvoice + @"% din valoarea comenzii efectuate)</b></td>
                                                        <td><b>" + totalInvoice + @"</b></td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <br/><br/>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align='center' style='background-color: #F5F5F5;'>
                                                <span style='font-family:Verdana; font-size:x-small;text-align:justify;'>
                                                    VA RUGAM SA EFECTUATI PLATA IN CONTUL INDICAT IN ANTETUL FACTURII PROFORME.
                                                </span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align='right'>
                                                <img src='" + ImageManagement.GetImage("scaune_ieftine_stampila.gif") + @"' alt='StampilaSemnatura' />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align='center' style='font-family:Verdana; font-size:xx-small;'>
                                               <b>" + myComp.ProviderName + @"</b>  " + myComp.ProviderAddress + @"<br/>
                                            </td>
                                        </tr>");

            contents.Append(@"       </tbody>
                               </table> 
                               <br/>
                             </center>
                           </body>
                         </html>");
            return contents.ToString();
        }

//        public string GetTextForRequest(Order order, Provider comp, IList<OrderDetail> detail)
//        {
//            // string clientRJ = order.Client.IsJuridical ? order.Client.ClientReg : string.Empty;
//            //string clientCUI = order.Client.IsJuridical ? order.Client.ClientCUI : string.Empty;

//            StringBuilder contents = new StringBuilder();
//            contents.Append(@"<html>
//                            <head>
//								<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
//									<style type='text/css'>
//										.style1 
//                                        {
//											font-family: Arial, Helvetica, sans-serif;
//											font-weight: bold;
//										}
//										.style5 
//                                        {
//											font-size: 12px;
//											font-family: Arial, Helvetica, sans-serif;
//										}
//										.style16 {font-family: Arial, Helvetica, sans-serif}
//										.style19 {font-size: 12px}
//										.style20 
//                                        {
//											font-family: Tahoma;
//											font-size: 10px;
//										}
//										.style22 {font-family: Arial, Helvetica, sans-serif; font-size: 9px; }
//										.style24 {font-size: 20px}
//										.style25 
//                                        {
//											font-size: 18px;
//											font-weight: bold;
//										}
//										.style27 {font-family: Arial, Helvetica, sans-serif; font-size: 12px; }
//										.style28 {font-size: 10px}
//										.style29 {
//															font-size: 14px; 
//															font-family: Arial, Helvetica, sans-serif;
//														 }
//										.style34 {
//															font-family: Arial, Helvetica, sans-serif;
//															font-size: 70px;
//															font-weight: bold;
//															color: __TodyBigColor__;
//														 }
//										.tableRejected {
//											border-style:outset;
//											border-width:5mm;
//											border-color:#B2B2B2;
//										}
//										.tableNormal {
//											border-width:1mm;
//											border-color:#B2B2B2;
//										}
//										/*table.tableNormal td {
//										border-width: 2px;
//										border-style: solid;
//										border-color: gray;
//										}
//										table.tableRejected td {
//										border-width: 2px;
//										border-style: solid;
//										border-color: gray;
//										}
//										table.tableNormal th {
//										border-width: 2px;
//										border-style: solid;
//										border-color: gray;
//										}
//										table.tableRejected th {
//										border-width: 2px;
//										border-style: solid;
//										border-color: gray;
//										}*/
//									</style>
//                            </head>
//                            <body marginwidth='0' marginheight='0' leftmargin='0' topmargin='0'>
//                              <center>");
//            contents.Append(@"      <table style='top:0px' border='1' width='850px'>
//                                    <tbody>
//                                        <tr>
//                                            <td align='center' style='font-family:Verdana; font-size:xx-small;'>
//                                                <b>" + comp.ProviderName + @"</b> " + comp.ProviderAddress + @" " + comp.City + @" " + comp.Region.RegionName + @"<br/> 
//                                                <span style='font-family: Broadway;font-size:large;'>
//                                                    <b>CERERE DE OFERTA NR. ;" + order.OrderId + @"</b>
//                                                 </span>
//                                            </td>
//                                        </tr>");
//            contents.Append(@"          <tr>
//                                            <td align='center' valign='center'>
//                                                <span style='font-family: Verdana;font-size:14px;font-weight: bold;'>
//                                                    <b> DETALII CORESPUNZATOARE COMENZII EFECTUATE </b>
//                                                </span>
//                                               <br/><br/>");
//            contents.Append(@"                  <table width='100%' border='2' style='font-family:Verdana; font-size:x-small;'>
//                                                    <thead style='border-width:medium;'>
//                                                        <tr>
//                                                            <th align='center'>Produs</th>
//                                                            <th align='center'>Material</th>
//                                                            <th align='center'>Cantitate</th>
//                                                            <th align='center'>Pret unitar fara Tva</th>
//                                                            <th align='center'>Valoare fara TVA</th>
//                                                            <th align='center'>Valoare TVA</th>
//                                                        </tr>
//                                                    </thead>
//                                                    <tbody>");
//            foreach (OrderDetail orderDetail in detail)
//            {
//                contents.Append(@"<tr>
//                                                            <td align='center'>" + orderDetail.ProductDetail.Product.ProductName + @"</td>
//                                                            <td align='center'>" + orderDetail.ProductDetail.Material.MaterialName + @"</td>
//                                                            <td align='right'>" + orderDetail.ProductCount + @"</td>
//                                                            <td align='right'>" + String.Format("{0:#.#,00}", orderDetail.ProductUnitPrice / (decimal)1.19) + @"</td>
//                                                            <td align='right'>" + String.Format("{0:#.#,00}", orderDetail.ProductTotalPrice / (decimal)1.19) + @"</td>
//                                                            <td align='right'>" + String.Format("{0:#.#,00}", (orderDetail.ProductTotalPrice / (decimal)1.19) * (decimal)0.19) + @"</td>
//                                                         </tr>");
//            }
//            contents.Append(@"<tr>
//                                                            <td align='left' colspan='4'>Total</td>
//                                                            <td align='right'>" + String.Format("{0:#.#,00}", order.TotalCost / (decimal)1.19) + @"</td>        
//                                                            <td align='right'>" + String.Format("{0:#.#,00}", order.TotalCost / (decimal)1.19) + @"</td>      
//                                                        </tr>");
//            contents.Append(@"<tr>
//                                                            <td align='left' colspan='4'>Total comanda</td>
//                                                            <td colspan='2' align='right'>" + order.TotalCost + @"</td>        
//                                                       </tr>");
//            contents.Append(@"                      </tbody>
//                                                </table>");
//            contents.Append(@"              </td>
//                                        </tr>
//                                        <tr>
//                                            <td>
//                                                <br/><br/>
//                                            </td>
//                                        </tr>
//                                        <tr>
//                                            <td align='center' style='font-family:Verdana; font-size:xx-small;'>
//                                               <b>" + comp.ProviderName + @"</b> " + comp.ProviderAddress + @"<br/>
//                                            </td>
//                                        </tr>");

//            contents.Append(@"       </tbody>
//                               </table> 
//                               <br/>
//                             </center>
//                           </body>
//                         </html>");
//            return contents.ToString();
//        }

          //<td align='center'>" + orderDetail.ProductDetail.Product.ProductName + @"</td>
          //                                                  <td align='center'>" + orderDetail.ProductDetail.Material.MaterialName + @"</td>
          //                                                  <td align='right'>" + orderDetail.ProductCount + @"</td>
    }
}
